﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Xml.Serialization;
using System.IO;

namespace Mimoza.TestPlugin
{
    public class ConfigPlugin : Mimoza.PluginLayer.IConfigPlugin
    {
        public ConfigPlugin()
        {
        }

        #region IConfigPlugin Members

        public string Identity
        {
            get { return "Mimoza.TestPlugin.ExecutePlugin"; }
        }

        public string Name
        {
            get 
            {
                return Resource.PluginName;
            }
        }

        public string Description
        {
            get 
            {
                return Resource.PluginDescription;
            }
        }

        public bool IsHardware
        {
            get 
            { 
                return true; 
            }
        }

        public System.Drawing.Icon Icon
        {
            get 
            {
                return Resource.PluginIcon;                
            }
        }

        public bool IsMultiple
        {
            get { return false; }
        }

        public string Serialize(object userData)
        {
            TestPluginData pluginData = userData as TestPluginData;

            if (pluginData == null)
            {
                Common.Logger.Log.Error(
                    "Mimoza.TestPlugin.ConfigPlugin error: userData is not correct");
                return null;
            }

            XmlSerializer serializer = new XmlSerializer(typeof(TestPluginData));
            TextWriter text = new StringWriter();
            serializer.Serialize(text, pluginData);
            return text.ToString();
        }

        public object Deserialize(string stringFrom)
        {
            if (stringFrom != null)
            {
                XmlSerializer deserializer = new XmlSerializer(typeof(TestPluginData));
                using (TextReader text = new StringReader(stringFrom))
                {
                    return deserializer.Deserialize(text);
                }
            }

            return new TestPluginData();
        }

        #endregion
#if !WindowsCE
        public IEnumerable<Mimoza.GUI.IWizardPage> Pages
        {
            get 
            {
                yield return new TestPluginConfigPage();
                yield return new TestPluginConfigPage1();
            }
        }

        public IEnumerable<Mimoza.GUI.IWizardPage> WizardPages
        {
            get 
            {
                yield return new TestPluginConfigPage();
                yield return new TestPluginConfigPage1();
            }
        }
#endif
    }
}
